package com.example.text.controller;

import com.example.text.service.ApiaccountService;
import com.example.text.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
public class AuthController {

    @Autowired
    private ApiaccountService apiaccountService;

    /**
     * 发送短信验证码
     */
    @PostMapping("/sms/send")
    public JsonResult sendSMSCode(@RequestParam String phone) {
        return apiaccountService.sendSMSCode(phone);
    }

    /**
     * 用户注册
     */
    @PostMapping("/register")
    public JsonResult register(@RequestParam String username,
                               @RequestParam String phone,
                               @RequestParam String password,
                               @RequestParam String smsCode) {
        return apiaccountService.register(username, phone, password, smsCode);
    }

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public JsonResult login(@RequestParam String account,
                            @RequestParam String password) {
        return apiaccountService.login(account, password);
    }
}